import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardGame {
    public static final String[] suits={"♣","♥","♦","♠"};
    public List<Card> buyCard(){
        List<Card> cardList = new ArrayList<Card>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit=suits[i];
                int rank=j;
                Card card=new Card(suit,rank);
                cardList.add(card);
            }
        }
        return cardList;
    }
    public void shuffle(List<Card> cardList){
        Random random = new Random();
        for(int i=cardList.size()-1;i>  0;i--){
            int index = random.nextInt(i);
            swap(cardList,index,i);
        }

    }
    private void swap(List<Card> cardList, int i, int j){
        //值得注意的是这里并非数组，需要通过面向对象的方式进行交换
        Card temp=cardList.get(i);//获取i
        cardList.set(i,cardList.get(j));//把i通过set更新为获取j
        cardList.set(j,temp);//最后把j更新为tmep
    }
}
